#!/bin/bash
morse_dir="/path/morse"
echo "校验 rongshu_testEnv_166.tar.gz md5"
# 获取文件的md5值
file_md5=$(md5sum "./rongshu_testEnv_166.tar.gz" | awk '{ print $1 }')
# 获取预期的md5值
expected_md5=a4759632b475ce5b8d375c39a443087a
# 比较md5值
if [ "$file_md5" = "$expected_md5" ]; then
    echo "File rongshu_testEnv_166.tar.gz is valid."
else
    echo "File rongshu_testEnv_166.tar.gz is invalid or corrupted."
    exit
fi
# 解压
tar -xvf rongshu_testEnv_166.tar.gz
# 校验第二个文件的md5值
echo "校验 166_pipei.tar.gz md5"
file_md5=$(md5sum "./166_pipei.tar.gz" | awk '{ print $1 }')
# 获取预期的md5值
expected_md5=1f3c4f0ed82cc92bbfb0e9e8259da805
# 比较md5值
if [ "$file_md5" = "$expected_md5" ]; then
    echo "File 166_pipei.tar.gz is valid."
else
    echo "File 166_pipei.tar.gz is invalid or corrupted."
    exit
fi
echo "解压 166_pipei.tar.gz"
tar -xvf 166_pipei.tar.gz
echo "加载镜像"
docker load -i 166_pipei.tar
echo "移动 docker-compose.yml文件和 config.yaml"
mv docker-compose.yml.166 $morse_dir
mv config.yaml.166 $morse_dir/conf
echo "停止原有服务并备份"
cd $morse_dir
docker-compose down
cp docker-compose.yml docker-compose.yml.1.52.0.$(date +%Y%m%d%H%M%S)
cp conf/config.yaml conf/config.yaml.1.52.0.$(date +%Y%m%d%H%M%S)
echo "替换新文件"
cat docker-compose.yml.166 > docker-compose.yml
cat conf/config.yaml.166 > conf/config.yaml
echo "启动服务"
docker-compose up -d
echo "`curl -k https://localhost/prod/ping`"

